#include <..\\standard.hlsli>
#include <..\\WR2Parameters.hlsli>

float4 ps_main(VertexToPixel PSIn) : SV_TARGET
{
	float3 Ln = -lightDir;
		float3 Nn = normalize(PSIn.normal);
		float3 In = normalize(PSIn.pos2.xyz - CameraPosition);// View direction
		float3 Hn = normalize(Ln - In);         // Half way between view & light
		//float3 R = reflect(In,Nn);                            //Env map

		float4 Lay1 = xColoredTexture1_Tex.Sample(Tex1, PSIn.texCoord1.xy);
		//float4 Lay2  = tex2D(Tex2, PSIn.texCoord1a.zw);

		if (Lay1.a < 0.5)
		{
		discard;
		}

	float ShadowCol = smoothstep(0.4375, 0.5625, 1.0 - PSIn.kBlend.w);
	float Diff = max(0.0, dot(Nn, Ln));
	float Spec = pow(max(0.0, dot(Nn, Hn)), 16.)*ShadowCol*0.5;

	float3 TexColor = Lay1.rgb*(1. + Spec);

	return float4(TexColor*(SunColor*Diff*ShadowCol + PSIn.kColor.rgb), 1);

}